package test;

public class SynchronizedEntity implements Runnable {
private static int i = 100;
private String key = "2";

@Override
public void run() {
	test1();
}

public synchronized void test1(){
	while(i>80){
	System.out.println("process name: "+Thread.currentThread().getName()+" i: "+--i);
	try {
		Thread.currentThread().sleep(500);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
	}
}
 
public void test2(){
	synchronized (this) {
		while(i>80)
		System.out.println("process name: "+Thread.currentThread().getName()+" i: "+--i);
	}
}
public void test3(){
	synchronized (key) {
		while(i>80)
		System.out.println("process name: "+Thread.currentThread().getName()+" i: "+--i);
	}
}
public synchronized static void test4(){
	while(i>80)
		System.out.println("process name: "+Thread.currentThread().getName()+" i: "+--i);
}
}
